<?php

declare(strict_types=1);

namespace App\Library;

use Hyperf\Utils\ApplicationContext;

class RedisLib
{


    private $redis;


    // 私有化构造方法
    private function __construct()
    {
        $this->redis = ApplicationContext::getContainer()->get(\Redis::class);
    }

    // 私有化clone方法
    private function __clone()
    {

    }


    // 保存实例的静态对象
    public static $singleInstance;

    /**
     * 声明静态调用方法
     * 目的：保证该方法的调用全局唯一
     *
     * @return XiaozhuaiSingleton
     */
    public static function getInstance()
    {
        if (!self::$singleInstance) {
            self::$singleInstance = new self();
        }

        return self::$singleInstance;
    }


    public function setex($key, $value, $expire){
        return $this->redis->setex($key, $expire, $value);
    }

    public function setnx($key,$value){
        return $this->redis->setnx($key,$value);
    }

    public function seget($key){
        return $this->redis->get($key);
    }

    public function del($key){
        return $this->redis->del($key);
    }


}
